# Contributor: Andres Almiray <aalmiray@yahoo.com>
# Maintainer: Andres Almiray <aalmiray@yahoo.com>
pkgname=jreleaser
pkgver=1.12.0
pkgrel=0
pkgdesc="Release projects quickly and easily with JReleaser"
url="https://jreleaser.org/"
# aarch64: openjdk currently segfaults
# ppc64le: openjdk hangs
# riscv64, 32-bit: no jdk11
arch="all !aarch64 !ppc64le !armv7 !armhf !x86 !riscv64"
license="Apache-2.0"
depends="openjdk11-jdk"
makedepends="gradle"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/jreleaser/jreleaser/archive/refs/tags/v$pkgver.tar.gz"
options="!check" #Check occurs in build

prepare() {
	default_prepare

	# generate a copy of the wrapper with the chosen version
	mkdir "$srcdir"/temp
	cd "$srcdir"/temp
	echo "rootProject.name = 'wrapper-project'" > settings.gradle
	# this will fetch an older version of gradle
	gradle --no-daemon wrapper --gradle-version 8.7

	cd "$builddir"

	# copy wrapper files into source distribution
	cp -r "$srcdir"/temp/gradlew* "$builddir"
	cp -r "$srcdir"/temp/gradle/* "$builddir"/gradle/
}

build() {
	# build requires Java 11
	export JAVA_HOME="/usr/lib/jvm/java-11-openjdk"
	./gradlew --no-daemon -PreproducibleBuild=true -x :jreleaser:setupJdks :jreleaser:distZip
}

package() {
	unzip -qo plugins/jreleaser/build/distributions/jreleaser-$pkgver.zip

	local apphome="/usr/share/java/jreleaser"
	local destdir="$pkgdir/$apphome"

	rm "jreleaser-$pkgver"/bin/*.bat
	install -Dm755 "jreleaser-$pkgver"/bin/* -t "$destdir"/bin

	mkdir -p "$pkgdir"/usr/bin
	ln -sf ../share/java/jreleaser/bin/jreleaser "$pkgdir"/usr/bin/jreleaser

	install -Dm644 "jreleaser-$pkgver"/lib/*.jar -t "$destdir"/lib
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

sha512sums="
fa1740332a7306c32e4995f4a2fd80fcfe7f11c5a49eeea1afd060657d9f8806d1366960b2914afbebe6a2610ff8720ee355c214e904e4479f04b4f398b5bee5  jreleaser-1.12.0.tar.gz
"

